package com.cnhaimei.vod.logic;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.SeekBar;
import android.widget.TextView;

import com.cnhaimei.com.PopupWindowEx;
import com.cnhaimei.vod.R;
import com.cnhaimei.vod.net.XVod;
import com.cnhaimei.vod.net.dc.Player;
import com.cnhaimei.vod.util.Const;

/**
 * 灯光控制
 * 
 * @author funwell@gmail.com <br>
 * @date 2013-8-20
 * 
 */
public class LightSetActivity extends VODActivity {

	View lightRouHe;
	View lightLangMan;
	View lightJiQing;
	View lightMengLong;
	View lightJingYan;
	View lightMingMei;
	View lightDongGan;
	View lightMingLiang;	

	View light1;
	View light2;
	View light3;
	View light4;
	View light5;
	View light6;
	
	private PopupWindowEx mPopupWindows;
	TextView popupTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.v8_light_set);

		initView();
		refreshView();
		XVod.G().registerListener(EventsManager.Event.PLYER_STATE, this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		XVod.G().unRegisterListener(EventsManager.Event.PLYER_STATE, this);
	}

	public void onEvent(int event, Object obj, boolean isSuc) {
		switch (event) {
		case EventsManager.Event.PLYER_STATE:
			refreshView();
			break;
		default:
			break;
		}
		super.onEvent(event, obj, isSuc);
	}

	@Override
	public void onClick(View v) {
		final Player p = Player.G();
		int id = v.getId();
		switch (id) {
		case R.id.goback:
			close();
			break;
		case R.id.rouhe:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.RouHe);
			break;
		case R.id.langman:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.LangMan);//
			break;
		case R.id.jiqing:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.JiQing);
			break;
		case R.id.menglong:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.MengLong);//
			break;
		case R.id.jingyan:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.JingYan);
			break;
		case R.id.mingmei:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.MingMei);
			break;
		case R.id.donggan:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.DongGan);
			break;
		case R.id.mingliang:
			XVod.G().setPlayerSet(Player.PLAYER_SET_LIGHT, Const.LIGHT.MingLiang);
			break;

		case R.id.light_1:
			break;
		case R.id.light_2:
			break;
		case R.id.light_3:
			break;
		case R.id.light_4:
			break;
		case R.id.light_5:
			break;
		case R.id.light_6:
			break;
			
		default:
			super.onClick(v); // need parent
			break;
		}

	}

	private void initView() {
		setTitle("灯光控制");
		showBackBtn(true);
		
		setClickable(R.id.light_1, R.id.light_2, R.id.light_3,	R.id.light_4, R.id.light_5, R.id.light_6);
		setClickable(R.id.rouhe, R.id.langman, R.id.jiqing, R.id.menglong, R.id.jingyan, R.id.donggan, R.id.mingmei, R.id.mingliang);
		setFocusable(R.id.light_1, R.id.light_2, R.id.light_3,	R.id.light_4, R.id.light_5, R.id.light_6);
		setFocusable(R.id.rouhe, R.id.langman, R.id.jiqing, R.id.menglong, R.id.jingyan, R.id.donggan, R.id.mingmei, R.id.mingliang);
		
		lightRouHe = findViewById(R.id.rouhe);
		lightLangMan = findViewById(R.id.langman);
		lightJiQing = findViewById(R.id.jiqing);
		lightMengLong = findViewById(R.id.menglong);
		lightJingYan = findViewById(R.id.jingyan);
		lightMingMei = findViewById(R.id.mingmei);
		lightDongGan = findViewById(R.id.donggan);
		lightMingLiang = findViewById(R.id.mingliang);

		light1 = findViewById(R.id.light_1);
		light2 = findViewById(R.id.light_2);
		light3 = findViewById(R.id.light_3);
		light4 = findViewById(R.id.light_4);
		light5 = findViewById(R.id.light_5);
		light6 = findViewById(R.id.light_6);
		
	}

	private void refreshView() {
		final Player p = Player.G();

		if (p.getLightState() == Const.LIGHT.RouHe) {
			lightRouHe.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightRouHe.setSelected(true);
		} else {
			lightRouHe.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightRouHe.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.LangMan) {
			lightLangMan.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightLangMan.setSelected(true);
		} else {
			lightLangMan.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightLangMan.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.JiQing) {
			lightJiQing.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightJiQing.setSelected(true);
		} else {
			lightJiQing.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightJiQing.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.MengLong) {
			lightMengLong.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightMengLong.setSelected(true);
		} else {
			lightMengLong.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightMengLong.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.JingYan) {
			lightJingYan.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightJingYan.setSelected(true);
		} else {
			lightJingYan.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightJingYan.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.MingMei) {
			lightMingMei.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightMingMei.setSelected(true);
		} else {
			lightMingMei.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightMingMei.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.DongGan) {
			lightDongGan.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightDongGan.setSelected(true);
		} else {
			lightDongGan.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightDongGan.setSelected(false);
		}

		if (p.getLightState() == Const.LIGHT.MingLiang) {
			lightMingLiang.setBackgroundResource(R.drawable.v8_dengguang_commonp);
			lightMingLiang.setSelected(true);
		} else {
			lightMingLiang.setBackgroundResource(R.drawable.v8_dengguang_common);
			lightMingLiang.setSelected(false);
		}

	}

	private void close() {
		finish();
	}
	
}
